#ifndef LCODEBLOCKIMPL_HPP
#define LCODEBLOCKIMPL_HPP

#include<Lcode/l_code.h>

#include"../cg/Node.hpp"
#include"../cg/BlockImpl.hpp"

class LcodeBlockImpl:public BlockImpl{
private:
	struct LcodeFlowInfo:public FlowInfo
	{
		L_Flow * flow;
		LcodeFlowInfo(L_Flow * flow): flow(flow)
		{
		}

		virtual FlowInfo *get_next()const
		{
			if( flow->next_flow == NULL)
				return NULL;
			else
				return static_cast<FlowInfo*>(new LcodeFlowInfo(flow->next_flow));
		}
		virtual int get_src_id()const
		{
			return flow->src_cb->id;
		}
		virtual int get_dest_id()const
		{
			return flow->dst_cb->id;
		}
	};
	L_Cb * cb;
	Operation<START_NODE>* build_startnode();
	Operation<END_NODE>* build_endnode();
	Node* new_node(L_Oper * &oper);
public:
	L_Cb * get_cb()const
	{
		return cb;
	}
	int getID()const
	{
		return cb->id;
	}

	FlowInfo *get_dest_flow()const
	{
		return cb->dest_flow == NULL ? NULL : static_cast<FlowInfo*>(new LcodeFlowInfo(cb->dest_flow));
	}
	FlowInfo *get_src_flow()const
	{
		return cb->src_flow == NULL ? NULL : static_cast<FlowInfo*>(new LcodeFlowInfo(cb->src_flow));
	}
	virtual enum BLKType get_block_type() const;
	virtual void build_nodelist(NodeSequence &nodelist);

	LcodeBlockImpl(L_Cb * cb);
	virtual ~LcodeBlockImpl()
	{

	}
};

#endif
